$(function () {
	
    var show_login_box = false;//variable for visibility of login box
    
    /*if a mouse click appears*/
    $('body').click( function(e) {
       if(e.target.id == 'header_login_link') {//if Login link is clicked
           if(show_login_box) {//if login box is visible
               setLoginBoxVisible(false);
           } else {//if login box is hidden
               setLoginBoxVisible(true);
           }
       } else if(e.target.id != ('header_login_link' && 'login_box') 
                    && $(e.target).closest("#login_box").size() == 0
                    && show_login_box){
           setLoginBoxVisible(false);
       }
    });
	
});
    
/*Function for showing or hiding the login box*/
function setLoginBoxVisible(visible) {
	if(visible) {
		$('#login_box').show("slow");
		$('#login_link_container').show("fast");
		show_login_box = true;
	} else {
		$('#login_box').hide("fast");
		$('#login_link_container').hide("fast");
		show_login_box = false;
	}
}